#include <memory>

#include "yuechuan.h"

yuechuan::Logger::ptr g_logger = YUECHUAN_LOG_ROOT();

void run_int_fiber()
{
    YUECHUAN_LOG_INFO(g_logger) << "run_in_fiber begin";
    yuechuan::Fiber::YieldToHold();                         
    YUECHUAN_LOG_INFO(g_logger) << "run_in_fiber end";
    yuechuan::Fiber::YieldToHold();
}
void test_fiber()
{
    yuechuan::Fiber::GetThis();
    YUECHUAN_LOG_INFO(g_logger) << " main begin ";
    yuechuan::Fiber::ptr fiber(new yuechuan::Fiber(run_int_fiber));
    fiber->swapIn();
    YUECHUAN_LOG_INFO(g_logger) << "main after swapIn";
    fiber->swapIn();
    YUECHUAN_LOG_INFO(g_logger) << "main after end";
    fiber->swapIn();


}
int main(int argc, char **argv)
{
    yuechuan::Thread::setName("main");
    std::vector<yuechuan::Thread::ptr> vec;
    for (int i=0; i <3 ;++i){
        vec.emplace_back(std::make_shared<yuechuan::Thread>(&test_fiber, "name_" + std::to_string(i)));
    }
    for(auto& i: vec){
        i->join();
    }
     YUECHUAN_LOG_INFO(g_logger) << "main after end2";


    return 0;
}